﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace DotNet.WebUI.ADO
{
    public partial class RptSqlHelper : BasicPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                FillData();
            }
        }

        private void FillData()
        {
            string _Sql = @"SELECT *
                FROM TB_Users ";

            rptUsers.DataSource = ExecuteDatasetBySql(_Sql);
            rptUsers.DataBind();
        }

        protected void rptData_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName.ToLower())
            {
                case "edit":
                    Response.Redirect(string.Format("UsersEdit.aspx?Operate=Edit&LoginID={0}", e.CommandArgument));
                    break;
                case "del":
                    string sql = @"DELETE FROM TB_Users
                        WHERE LoginID = '{0}' ";
                    sql = string.Format(sql, e.CommandArgument.ToString());
                    ExecuteNonQueryBySql(sql);
                    break;
                case "pwd":
                    ExecuteNonQueryBySql(string.Format(@"UPDATE TB_Users Set Pwd ='{1}'
                        WHERE LoginID = '{0}' ", e.CommandArgument.ToString(), "123456"));
                    break;
            }
            FillData();
        }
    }
}